<?php
/**
 * Created by PhpStorm.
 * User: lullabies
 * Date: 2019/5/23
 * Time: 21:30
 */

namespace app\api\model;
use think\Model;

class Grade extends Model
{
    /**
     * 根据用户id 获取当前考试下的科目信息
     */
    public static function getInfoByUserId($user_id,$exam_id){
        $result = self::where(['user_id'=>$user_id,'exam_id'=>$exam_id])
            ->select();
        return $result;
    }
    /**
     * 根据科目和用户id获取当前学生排名信息
     */
    public static function getRankBySubject($subject_id,$user_id){
        $result = self::field('score,username,subject_name')
            ->query("select count(distinct score) from art_grade as s2 where s2.score>=s1.score rank")
            ->alias('s1')
            ->where(['subject_id' =>$subject_id,'user_id'=>$user_id])
            ->order('score','desc')
            ->select();
        return $result;
    }
}